﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of a message queue for inter-thread communication.</summary>
	// Token: 0x0200004A RID: 74
	public class HMessageQueue : HHandle
	{
		// Token: 0x06000A1F RID: 2591 RVA: 0x000407E8 File Offset: 0x0003E9E8
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HMessageQueue(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000A20 RID: 2592 RVA: 0x000407F7 File Offset: 0x0003E9F7
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HMessageQueue(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x06000A21 RID: 2593 RVA: 0x00040806 File Offset: 0x0003EA06
		private void AssertSemType()
		{
			base.AssertSemType("message_queue");
		}

		// Token: 0x06000A22 RID: 2594 RVA: 0x00040813 File Offset: 0x0003EA13
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HMessageQueue obj)
		{
			obj = new HMessageQueue(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000A23 RID: 2595 RVA: 0x0004082C File Offset: 0x0003EA2C
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HMessageQueue[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HMessageQueue[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HMessageQueue(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Create a new empty message queue.
		///   Modified instance represents: Handle of the newly created message queue.
		/// </summary>
		// Token: 0x06000A24 RID: 2596 RVA: 0x0004089C File Offset: 0x0003EA9C
		public HMessageQueue()
		{
			IntPtr proc = HalconAPI.PreCall(533);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Query message queue parameters or information about the queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="genParamName">Names of the queue parameters or info queries. Default: "max_message_num"</param>
		/// <returns>Values of the queue parameters or info queries.</returns>
		// Token: 0x06000A25 RID: 2597 RVA: 0x000408E0 File Offset: 0x0003EAE0
		public HTuple GetMessageQueueParam(HTuple genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(528);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query message queue parameters or information about the queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="genParamName">Names of the queue parameters or info queries. Default: "max_message_num"</param>
		/// <returns>Values of the queue parameters or info queries.</returns>
		// Token: 0x06000A26 RID: 2598 RVA: 0x00040938 File Offset: 0x0003EB38
		public HTuple GetMessageQueueParam(string genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(528);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Set message queue parameters or invoke commands on the queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="genParamName">Names of the queue parameters or action commands. Default: "max_message_num"</param>
		/// <param name="genParamValue">Values of the queue parameters or action commands. Default: 1</param>
		// Token: 0x06000A27 RID: 2599 RVA: 0x00040988 File Offset: 0x0003EB88
		public void SetMessageQueueParam(HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(529);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Set message queue parameters or invoke commands on the queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="genParamName">Names of the queue parameters or action commands. Default: "max_message_num"</param>
		/// <param name="genParamValue">Values of the queue parameters or action commands. Default: 1</param>
		// Token: 0x06000A28 RID: 2600 RVA: 0x000409D8 File Offset: 0x0003EBD8
		public void SetMessageQueueParam(string genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(529);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Receive one or more messages from the message queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="genParamName">Names of optional generic parameters Default: "timeout"</param>
		/// <param name="genParamValue">Values of optional generic parameters Default: "infinite"</param>
		/// <returns>Handle(s) of the dequeued message(s).</returns>
		// Token: 0x06000A29 RID: 2601 RVA: 0x00040A24 File Offset: 0x0003EC24
		public HMessage[] DequeueMessage(HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(530);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HMessage[] result;
			num = HMessage.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Receive one or more messages from the message queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="genParamName">Names of optional generic parameters Default: "timeout"</param>
		/// <param name="genParamValue">Values of optional generic parameters Default: "infinite"</param>
		/// <returns>Handle(s) of the dequeued message(s).</returns>
		// Token: 0x06000A2A RID: 2602 RVA: 0x00040A88 File Offset: 0x0003EC88
		public HMessage DequeueMessage(string genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(530);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamValue);
			HMessage result;
			num = HMessage.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Enqueue one or more messages to the message queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="messageHandle">Handle(s) of message(s) to be enqueued.</param>
		/// <param name="genParamName">Names of optional generic parameters.</param>
		/// <param name="genParamValue">Values of optional generic parameters.</param>
		// Token: 0x06000A2B RID: 2603 RVA: 0x00040AE8 File Offset: 0x0003ECE8
		public void EnqueueMessage(HMessage[] messageHandle, HTuple genParamName, HTuple genParamValue)
		{
			HTuple htuple = HHandleBase.ConcatArray(messageHandle);
			IntPtr proc = HalconAPI.PreCall(531);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, htuple);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(messageHandle);
		}

		/// <summary>
		///   Enqueue one or more messages to the message queue.
		///   Instance represents: Message queue handle.
		/// </summary>
		/// <param name="messageHandle">Handle(s) of message(s) to be enqueued.</param>
		/// <param name="genParamName">Names of optional generic parameters.</param>
		/// <param name="genParamValue">Values of optional generic parameters.</param>
		// Token: 0x06000A2C RID: 2604 RVA: 0x00040B58 File Offset: 0x0003ED58
		public void EnqueueMessage(HMessage messageHandle, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(531);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, messageHandle);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
			GC.KeepAlive(messageHandle);
		}

		/// <summary>Close a message queue handle and release all associated resources.</summary>
		/// <param name="queueHandle">Message queue handle(s) to be closed.</param>
		// Token: 0x06000A2D RID: 2605 RVA: 0x00040BB8 File Offset: 0x0003EDB8
		public static void ClearMessageQueue(HMessageQueue[] queueHandle)
		{
			HTuple htuple = HHandleBase.ConcatArray(queueHandle);
			IntPtr proc = HalconAPI.PreCall(532);
			HalconAPI.Store(proc, 0, htuple);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(htuple);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(queueHandle);
		}

		/// <summary>
		///   Close a message queue handle and release all associated resources.
		///   Instance represents: Message queue handle(s) to be closed.
		/// </summary>
		// Token: 0x06000A2E RID: 2606 RVA: 0x00040BFC File Offset: 0x0003EDFC
		public void ClearMessageQueue()
		{
			IntPtr proc = HalconAPI.PreCall(532);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Create a new empty message queue.
		///   Modified instance represents: Handle of the newly created message queue.
		/// </summary>
		// Token: 0x06000A2F RID: 2607 RVA: 0x00040C30 File Offset: 0x0003EE30
		public void CreateMessageQueue()
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(533);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}
	}
}
